export default {
    data() {
        return {
            dialogImageUrl: "",
            // dialogVisible: false,
            disabled: false,
            fileList: [],
            updataUrl: `${this.$updata}api/index/uploads`,
            token: window.localStorage.token
        }
    },
    methods: {
        handleRemove(file) {
            this.fileList.forEach((v, index) => {
                v.uid == file.uid && this.fileList.splice(index, 1);
            });
            this.$forceUpdate();
        },
        handlePictureCardPreview(file) {

            this.$get('/api/index/download', {
                file: file.url
            }).then(res => {
                // console.log(file.url.split('.'))
                let a = file.url.split('.').pop()
                if (a == 'pdf') {
                    if (res.code != 100) {
                        window.open(file.fullUrl);
                    }
                } else {
                    this.$message({
                        message: '该文件不是pdf文件',
                        type: 'error'
                    })
                }

            })
        },
        handleDownload(file) {
            // let lastName = file.url.split('.').pop()
            this.$get('/api/index/download', {
                file: file.url
            })
            // .then(res => {
            //     const url = window.URL.createObjectURL(new Blob([res]));
            //     var a = document.createElement('a')
            //     a.href = url

            //     a.download = `附件.${lastName}`


            //     a.click()
            // })
            // window.open(file.fullUrl)
            // document.body.appendChild(a).click()
            // a.setAttribute('download','file.name')
        },
        updataFileSuccess(response, file) {
            // this.fileList.push({
            //     url: `${response.code}`,
            //     fullUrl: `${this.$updata}${response.code}`
            // })
            file.url = `${response.code}`
            file.fullUrl = `${this.$updata}${response.code}`
            this.$message.success("文件上传成功");
        },
        updataFileError(err) {
            console.log(err);
            this.$message.error("文件上传失败");
        },
        uploadChange(file, fileList) {
            // console.log(file.name.split('.').splice(-1, 1))
            this.fileList = fileList;
        }
    }
}